<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>推送消息</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
            $("#pushType").on(selChange());
            getAppid();
		});


        function selChange() {
            var pushType = document.getElementById("pushType").selectedIndex;
            console.log("pushType changed: " + pushType);
            if (pushType == 0) {
                $("#s_id").hide();
            }
            if (pushType == 1) {
                $("#s_id").show();
                $("#pushAliasTag").empty();
                getAliasOrTag('alias');
            }
            if (pushType == 2) {
                $("#s_id").show();
                $("#pushAliasTag").empty();
                getAliasOrTag('tag');
            }
        }

        function getAliasOrTag(dictType) {
            var value = dictType;
            $.ajax({
                async: false,
                type: "post",
                url: "${ctx}/notify/notiMessage/pushMessageByTagOrAlias",
                data: {dictType: value},
                success: function (data) {
                    $("#pushAliasTag").empty();
//                    $("#pushAliasTag").append("<option  class='options'>" +"--请选择--"+ "</option>");
                    console.log("pushType data: " + data);
                    for (var i = 0; i < data.length; i++) {
                            $("#pushAliasTag").append("<option  class='options' value='" + data[i] + "'>" + data[i] + "</option>");
                    }
                }
            })
        }

        function getAppid() {
            $.ajax({
                async: false,
                type: "post",
                url: "${ctx}/notify/notiApp/getAppid",
//                data: {dictType: 'tag'},
                success: function (data) {
                    console.log("pushType 哈哈: " + data);
                    for (var i = 0; i < data.length; i++) {
                        $("#appid").append("<option  class='options' value='" + data[i] + "'>" + data[i] + "</option>");
                    }
                }
            })
        }





	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/notify/notiMessage/">推送历史</a></li>
		<li class="active"><a href="${ctx}/notify/notiMessage/form?id=${notiMessage.id}">推送消息
			<%--<shiro:hasPermission name="notify:notiMessage:edit">${not empty notiMessage.id?'修改':'添加'}</shiro:hasPermission>--%>
			<%--<shiro:lacksPermission name="notify:notiMessage:edit">查看</shiro:lacksPermission>--%></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="notiMessage" action="${ctx}/notify/notiMessage/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
            <label class="control-label">消息标题：</label>
			<div class="controls">
				<form:input path="msgTitle" htmlEscape="false" maxlength="1024" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">消息内容：</label>
			<div class="controls">
				<form:textarea path="msgContent" htmlEscape="false" maxlength="1024" class="input-xlarge "/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">app版本：</label>
			<div class="controls">
				<form:input path="appedition" htmlEscape="false" maxlength="20" class="input-xlarge"/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">推送appid：</label>
			<div class="controls">
				<form:select path="appid" htmlEscape="false" maxlength="1024" class="input-xlarge ">
					<option>--请选择--</option>
				</form:select>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">推送平台：</label>
			<div class="controls">
				<%--<form:input path="pushPlatform" htmlEscape="false" maxlength="20" class="input-xlarge "/>--%>
					<form:select path="pushPlatform" class="input-medium">
						<form:option value="all" label="all"/>
						<form:option value="android" label="android"/>
						<form:option value="apple" label="apple"/>
						<form:option value="winphone" label="winphone"/>
					</form:select>
			</div>
		</div>

		<div class="control-group" style="display: inline-block;width: 345px;">
			<label class="control-label">推送类型/目标：</label>
			<div class="controls">
				<form:select path="pushType" htmlEscape="false" maxlength="20" class="input-medium"
							 onchange="selChange()">
					<form:option value="broadcast" label="broadcast"/>
					<form:option value="alias" label="alias"/>
					<form:option value="tag" label="tag"/>
				</form:select>
			</div>
		</div>

		<div id="s_id" class="control-group" style="display: inline-block">
			<div class="controls" style="margin-left: 0">
					<%--<select id="pushAliasTag" maxlength="20"  class="input-medium">
                        &lt;%&ndash;<option value="默认" selected="selected">默认</option>&ndash;%&gt;
                    </select>--%>
				<form:select path="pushAliasTag" class="input-medium">
                    <option>--请选择--</option>
				</form:select>
			</div>
		</div>


		<%--<div class="control-group">--%>
			<%--<label class="control-label">安卓推送总数：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input path="pushAndroidToal" htmlEscape="false" maxlength="20" class="input-xlarge  digits"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">安卓推送成功数：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input path="pushAndroidSuccess" htmlEscape="false" maxlength="20" class="input-xlarge  digits"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">苹果推送总数：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input path="pushAppleToal" htmlEscape="false" maxlength="20" class="input-xlarge  digits"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">苹果推送成功数：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input path="pushAppleSuccess" htmlEscape="false" maxlength="20" class="input-xlarge  digits"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">winphone推送总数：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input path="pushWinphoneToal" htmlEscape="false" maxlength="20" class="input-xlarge  digits"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">winphone推送成功数：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input path="pushWinphoneSuccess" htmlEscape="false" maxlength="20" class="input-xlarge  digits"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="notify:notiMessage:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="立即发送并保存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>


</body>
</html>